package com.mdxq.springboot04_mybatis_plus.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author WanJl
 * @version 1.0
 * @title MybatisPlusConfig
 * @description mybatis-plus自带的分页插件，3.5.x版本被砍掉了。因为用的人少。我们后续用的更多的是【PageHelper分页插件】
 *
 * @create 2024/11/18
 */
@Configuration
public class MybatisPlusConfig {
    //Spring向IOC容器注入第三方的Bean
    @Bean
    public MybatisPlusInterceptor getMybatisPlusInterceptor() {
        //1、创建MybatisPlus分页拦截器对象
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //2、添加分页拦截器
        //interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); // 如果配置多个插件, 切记分页最后添加

        //乐观锁拦截器
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }
}
